package com.bjsxt.userscenter.users.pojo;

import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.bjsxt.userscenter.common.util.DateFormatUtil;

/**
 * 管理员的POJO
 * 
 * @author wangshSxt
 *
 */
public class AAdmins
{
	private int id;
	private int roleId;
	private String email;
	private String password;
	private String trueName;
	private String phone;
	private String qq;
	private int loginFailedCount;
	private Date loginFailedTime;
	private byte status;
	private Date createTime;
	private Date updateTime;
	private Date lastLoginTime;
	
	/* 字符串描述 */
	private String statusStr ; 
	
	/* 关联关系 */
	private ARole role ; 

	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public int getRoleId()
	{
		return roleId;
	}

	public void setRoleId(int roleId)
	{
		this.roleId = roleId;
	}

	public String getEmail()
	{
		return email;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public String getTrueName()
	{
		return trueName;
	}

	public void setTrueName(String trueName)
	{
		this.trueName = trueName;
	}

	public String getPhone()
	{
		return phone;
	}

	public void setPhone(String phone)
	{
		this.phone = phone;
	}

	public String getQq()
	{
		return qq;
	}

	public void setQq(String qq)
	{
		this.qq = qq;
	}

	public int getLoginFailedCount()
	{
		return loginFailedCount;
	}

	public void setLoginFailedCount(int loginFailedCount)
	{
		this.loginFailedCount = loginFailedCount;
	}

	public Date getLoginFailedTime()
	{
		return loginFailedTime;
	}

	public void setLoginFailedTime(Date loginFailedTime)
	{
		this.loginFailedTime = loginFailedTime;
	}

	public byte getStatus()
	{
		return status;
	}

	public void setStatus(byte status)
	{
		this.status = status;
	}

	public Date getCreateTime()
	{
		return createTime;
	}

	public void setCreateTime(Date createTime)
	{
		this.createTime = createTime;
	}

	public Date getUpdateTime()
	{
		return updateTime;
	}

	public void setUpdateTime(Date updateTime)
	{
		this.updateTime = updateTime;
	}

	public Date getLastLoginTime()
	{
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime)
	{
		this.lastLoginTime = lastLoginTime;
	}

	public ARole getRole()
	{
		return role;
	}

	public void setRole(ARole role)
	{
		this.role = role;
	}
	
	public JSONObject toJSON()
	{
		DateFormatUtil dateFormatUtil = new DateFormatUtil();
		/* 存储到Token的容器中,值为管理员对应的JSON信息 */
		JSONObject adminsJSON = new JSONObject();
		/* 存储管理员对象可开放的字段 */
		adminsJSON.put("id", this.getId());
		adminsJSON.put("email", this.getEmail());
		adminsJSON.put("trueName", this.getTrueName());
		adminsJSON.put("createTime", dateFormatUtil.format(this.getCreateTime()));
		adminsJSON.put("updateTime", dateFormatUtil.format(this.getUpdateTime()));
		adminsJSON.put("lastLoginTime", dateFormatUtil.format(this.getLastLoginTime()));
		return adminsJSON ; 
	}

	public String getStatusStr()
	{
		/*
		 * 状态:0:禁用;1:启用
		 * */
		AAdminsEnum[] adminsEnums = AAdminsEnum.values();
		for (int i = 0; i < adminsEnums.length; i++)
		{
			AAdminsEnum adminsEnum = adminsEnums[i];
			if(adminsEnum.toString().startsWith("STATUS_"))
			{
				/* 如果循环的枚举==数据库存储的状态值,赋值枚举指定的字符串 */
				if(adminsEnum.getStatus() == this.status)
				{
					this.statusStr = adminsEnum.getInfo();
					break ; 
				}
			}
		}
		return statusStr;
	}
}
